sys

python运行环境相关接口;比如python的环境变量,字符集

sys库常用参数 描述
sys.float_info 系统浮点数类型的参数信息
sys.int_info 系统整数类型的参数类型
sys.hash_info 系统哈希函数的参数类型
sys.thread_info 系统线程实现的参数信息
sys.byteorder 字节序标识,大端返回’big’,小端返回’little’
sys.executable 当前解释器可执行文件的绝对路径
sys.maxunicode 系统支持的最大unicode值,一般是1114111(0x10FFFF)
sys.path 解释器用来加载python库的路径列表
sys.argv 命令行参数的列表
sys.dont_write_bytecode 如果为True,则不生成.pyc字节码
sys库常用函数 描述
sys.getrecursionlimit() 获取系统递归最大深度
sys.setrecursionlimit(n) 设置系统递归最大升读为n
sys.getdefaultencoding() 获得当前默认的字符串编码名称
sys.getsizeof(objiect) 获得object的字节长度,object可以是任意类型
sys.exit([arg]) 退出python程序,可附带状态码arg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
>>>import sys	   
>>>sys.float_info
sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)
>>>sys.int_info
sys.int_info(bits_per_digit=15, sizeof_digit=2)
>>>sys.hash_info
sys.hash_info(width=32, modulus=2147483647, inf=314159, nan=0, imag=1000003, algorithm='siphash24', hash_bits=64, seed_bits=128, cutoff=0)
>>>sys.thread_info
sys.thread_info(name='nt', lock=None, version=None)
>>>sys.byteorder
'little'
>>>sys.executable
'C:\\Users\\xiaoy\\AppData\\Local\\Programs\\Python\\Python36-32\\pythonw.exe'
>>>sys.maxunicode
1114111
>>>sys.path
['C:/Users/Tian Song/AppData/Local/Programs/Python/Python36-32', 'C:\\Users\\Tian Song\\AppData\\Local\\Programs\\Python\\Python36-32\\Lib\\idlelib', 'C:\\Users\\Tian Song\\AppData\\Local\\Programs\\Python\\Python36-32\\python36.zip', 'C:\\Users\\Tian Song\\AppData\\Local\\Programs\\Python\\Python36-32\\DLLs', 'C:\\Users\\Tian Song\\AppData\\Local\\Programs\\Python\\Python36-32\\lib', 'C:\\Users\\Tian Song\\AppData\\Local\\Programs\\Python\\Python36-32', 'C:\\Users\\Tian Song\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages', 'C:\\Users\\Tian Song\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages\\win32', 'C:\\Users\\Tian Song\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages\\win32\\lib', 'C:\\Users\\Tian Song\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages\\Pythonwin']
>>>sys.getrecursionlimit()
1000
>>>sys.getdefaultencoding()
'utf-8'